<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Elasticsearch 核心指南 | 现代化搜索引擎架构解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #9333ea 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .concept-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            margin-right: 16px;
        }
        .section-divider {
            height: 1px;
            background: linear-gradient(90deg, rgba(79,70,229,0.1) 0%, rgba(79,70,229,0.5) 50%, rgba(79,70,229,0.1) 100%);
        }
        .highlight-box {
            border-left: 4px solid #4f46e5;
            background-color: rgba(79,70,229,0.05);
        }
        .nav-link {
            position: relative;
        }
        .nav-link:after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: -2px;
            left: 0;
            background-color: #4f46e5;
            transition: width 0.3s ease;
        }
        .nav-link:hover:after {
            width: 100%;
        }
        .active-nav:after {
            width: 100%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4 md:px-0">
        <div class="max-w-5xl mx-auto text-center">
            <div class="inline-block bg-white bg-opacity-20 px-4 py-2 rounded-full mb-6">
                <span class="text-sm font-medium">技术干货</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Elasticsearch 核心指南</h1>
            <p class="text-xl md:text-2xl text-white text-opacity-90 max-w-3xl mx-auto mb-10">
                现代化分布式搜索引擎架构解析与最佳实践
            </p>
            <div class="flex justify-center space-x-4">
                <a href="#core-concepts" class="bg-white text-indigo-600 px-6 py-3 rounded-lg font-medium hover:bg-opacity-90 transition-all duration-300">
                    核心概念
                </a>
                <a href="#architecture" class="border-2 border-white border-opacity-30 text-white px-6 py-3 rounded-lg font-medium hover:bg-white hover:bg-opacity-10 transition-all duration-300">
                    架构设计
                </a>
            </div>
        </div>
    </section>

    <!-- Navigation -->
    <nav class="sticky top-0 bg-white shadow-sm z-10">
        <div class="max-w-6xl mx-auto px-4">
            <div class="flex overflow-x-auto py-4 space-x-8">
                <a href="#core-concepts" class="nav-link text-gray-700 font-medium whitespace-nowrap active-nav">核心概念</a>
                <a href="#architecture" class="nav-link text-gray-500 font-medium whitespace-nowrap">架构设计</a>
                <a href="#query-aggregation" class="nav-link text-gray-500 font-medium whitespace-nowrap">查询与聚合</a>
                <a href="#optimization" class="nav-link text-gray-500 font-medium whitespace-nowrap">性能优化</a>
                <a href="#applications" class="nav-link text-gray-500 font-medium whitespace-nowrap">实际应用</a>
                <a href="#best-practices" class="nav-link text-gray-500 font-medium whitespace-nowrap">最佳实践</a>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="max-w-4xl mx-auto px-4 py-16">
        <!-- Core Concepts -->
        <section id="core-concepts" class="mb-24">
            <div class="flex items-center mb-12">
                <div class="bg-indigo-100 text-indigo-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                    <i class="fas fa-cube text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">1. Elasticsearch 的核心概念</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">1.1 什么是 Elasticsearch？</h3>
                <p class="text-lg text-gray-700 mb-6 leading-relaxed">
                    Elasticsearch 是一个基于 Lucene 的分布式搜索引擎，提供了近实时的搜索和分析能力。它能够处理大规模数据，并支持复杂的查询和聚合操作。
                </p>
                <div class="bg-indigo-50 rounded-xl p-6 mb-8">
                    <div class="flex items-start">
                        <div class="text-indigo-500 mr-4 mt-1">
                            <i class="fas fa-info-circle"></i>
                        </div>
                        <div>
                            <h4 class="font-bold text-gray-800 mb-2">核心特点</h4>
                            <ul class="list-disc list-inside text-gray-700 space-y-2">
                                <li>分布式架构，水平扩展能力强</li>
                                <li>近实时(NRT)的搜索能力</li>
                                <li>强大的全文搜索功能</li>
                                <li>丰富的聚合分析能力</li>
                                <li>支持多租户和多种数据类型</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">1.2 核心概念</h3>
                
                <div class="grid md:grid-cols-2 gap-6 mb-12">
                    <div class="bg-white p-6 rounded-xl shadow-sm card-hover">
                        <div class="flex items-start mb-4">
                            <div class="concept-icon bg-indigo-100 text-indigo-600">
                                <i class="fas fa-database text-xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold text-gray-800">索引(Index)</h4>
                                <p class="text-gray-600">类似于数据库中的表，用于存储相关文档。</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm card-hover">
                        <div class="flex items-start mb-4">
                            <div class="concept-icon bg-blue-100 text-blue-600">
                                <i class="fas fa-file-alt text-xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold text-gray-800">文档(Document)</h4>
                                <p class="text-gray-600">索引中的基本数据单元，通常以 JSON 格式存储。</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm card-hover">
                        <div class="flex items-start mb-4">
                            <div class="concept-icon bg-purple-100 text-purple-600">
                                <i class="fas fa-puzzle-piece text-xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold text-gray-800">分片(Shard)</h4>
                                <p class="text-gray-600">索引被分成多个分片，分布在不同的节点上，实现数据的分布式存储和查询。</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm card-hover">
                        <div class="flex items-start mb-4">
                            <div class="concept-icon bg-green-100 text-green-600">
                                <i class="fas fa-copy text-xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold text-gray-800">副本(Replica)</h4>
                                <p class="text-gray-600">每个分片可以有多个副本，用于提高数据的可用性和查询性能。</p>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="mb-12">
                    <div class="mermaid">
                        graph TD
                            A[集群 Cluster] --> B[节点 Node 1]
                            A --> C[节点 Node 2]
                            B --> D[索引 Index 1]
                            B --> E[索引 Index 2]
                            C --> D
                            C --> E
                            D --> F[主分片 Primary Shard]
                            D --> G[副本分片 Replica Shard]
                            E --> H[主分片 Primary Shard]
                            E --> I[副本分片 Replica Shard]
                    </div>
                </div>
            </div>
        </section>

        <!-- Architecture Design -->
        <section id="architecture" class="mb-24">
            <div class="flex items-center mb-12">
                <div class="bg-indigo-100 text-indigo-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                    <i class="fas fa-sitemap text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">2. Elasticsearch 的架构设计</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">2.1 分布式架构</h3>
                <p class="text-lg text-gray-700 mb-6 leading-relaxed">
                    Elasticsearch 采用分布式架构，数据被分成多个分片，分布在不同的节点上。这种设计不仅提高了数据的存储能力，还实现了查询的并行处理，显著提升了性能。
                </p>
                
                <div class="grid md:grid-cols-2 gap-8 mb-10">
                    <div>
                        <h4 class="text-xl font-semibold text-gray-800 mb-4">2.1.1 分片与副本</h4>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>分片</strong>：每个索引被分成多个分片，分片数量在创建索引时指定，之后不能更改。</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>副本</strong>：每个分片可以有多个副本，副本数量可以动态调整。副本不仅提高了数据的可用性，还分担了查询负载。</span>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h4 class="text-xl font-semibold text-gray-800 mb-4">2.1.2 节点角色</h4>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-server text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>主节点(Master Node)</strong>：负责集群的管理操作，如创建和删除索引、分配分片等。</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-database text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>数据节点(Data Node)</strong>：负责存储数据和执行查询。</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-network-wired text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>协调节点(Coordinating Node)</strong>：负责接收客户端请求，并将请求转发到相应的数据节点。</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm mb-10">
                    <div class="mermaid">
                        flowchart LR
                            Client -->|请求| CoordinatingNode
                            CoordinatingNode -->|路由| DataNode1
                            CoordinatingNode -->|路由| DataNode2
                            DataNode1 -->|结果聚合| CoordinatingNode
                            DataNode2 -->|结果聚合| CoordinatingNode
                            CoordinatingNode -->|响应| Client
                            MasterNode -.->|集群管理| DataNode1
                            MasterNode -.->|集群管理| DataNode2
                    </div>
                </div>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">2.2 近实时搜索</h3>
                <p class="text-lg text-gray-700 mb-6 leading-relaxed">
                    Elasticsearch 提供了近实时的搜索能力，文档在索引后几乎可以立即被搜索到。这是通过以下机制实现的：
                </p>
                
                <div class="grid md:grid-cols-2 gap-6 mb-8">
                    <div class="bg-indigo-50 p-6 rounded-xl">
                        <div class="flex items-center mb-3">
                            <div class="bg-indigo-100 text-indigo-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                                <i class="fas fa-sync-alt"></i>
                            </div>
                            <h4 class="text-lg font-semibold text-gray-800">刷新(Refresh)</h4>
                        </div>
                        <p class="text-gray-700">将内存中的文档写入到文件系统缓存中，使其可被搜索。默认每秒执行一次。</p>
                    </div>
                    
                    <div class="bg-purple-50 p-6 rounded-xl">
                        <div class="flex items-center mb-3">
                            <div class="bg-purple-100 text-purple-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                                <i class="fas fa-save"></i>
                            </div>
                            <h4 class="text-lg font-semibold text-gray-800">提交(Commit)</h4>
                        </div>
                        <p class="text-gray-700">将文件系统缓存中的文档写入到磁盘，确保数据的持久性。默认每30分钟或512MB数据后执行。</p>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">2.3 倒排索引</h3>
                <p class="text-lg text-gray-700 mb-6 leading-relaxed">
                    Elasticsearch 使用倒排索引(Inverted Index)来加速搜索。倒排索引将文档中的每个词映射到包含该词的文档列表，使得查询可以快速定位到相关文档。
                </p>
                
                <div class="bg-white p-6 rounded-xl shadow-sm mb-8">
                    <div class="mermaid">
                        graph LR
                            subgraph 倒排索引
                                A[term1] -->|文档1,3| B
                                C[term2] -->|文档2| B
                                D[term3] -->|文档1,2,3| B
                            end
                            subgraph 文档
                                B[文档1: term1, term3\n文档2: term2, term3\n文档3: term1, term3]
                            end
                    </div>
                </div>
                
                <div class="highlight-box p-6">
                    <div class="flex items-start">
                        <div class="text-indigo-500 mr-4">
                            <i class="fas fa-lightbulb"></i>
                        </div>
                        <div>
                            <h4 class="font-bold text-gray-800 mb-2">倒排索引优势</h4>
                            <ul class="list-disc list-inside text-gray-700 space-y-2">
                                <li>快速定位包含特定词汇的文档</li>
                                <li>支持高效的全文检索</li>
                                <li>支持相关性评分</li>
                                <li>适合处理海量文本数据</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Query & Aggregation -->
        <section id="query-aggregation" class="mb-24">
            <div class="flex items-center mb-12">
                <div class="bg-indigo-100 text-indigo-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                    <i class="fas fa-search text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">3. Elasticsearch 的查询与聚合</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">3.1 查询 DSL</h3>
                <p class="text-lg text-gray-700 mb-6 leading-relaxed">
                    Elasticsearch 提供了丰富的查询 DSL(Domain Specific Language)，支持复杂的查询操作。
                </p>
                
                <div class="grid md:grid-cols-2 gap-6 mb-10">
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <h4 class="text-xl font-semibold text-gray-800 mb-4">主要查询类型</h4>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-search text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>全文搜索</strong>：如 <code class="bg-gray-100 px-1 rounded">match</code>, <code class="bg-gray-100 px-1 rounded">multi_match</code> 查询</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-equals text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>精确匹配</strong>：如 <code class="bg-gray-100 px-1 rounded">term</code>, <code class="bg-gray-100 px-1 rounded">terms</code> 查询</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-arrows-alt-h text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>范围查询</strong>：如 <code class="bg-gray-100 px-1 rounded">range</code> 查询</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-code-branch text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>布尔查询</strong>：如 <code class="bg-gray-100 px-1 rounded">bool</code> 查询，支持 <code class="bg-gray-100 px-1 rounded">must</code>, <code class="bg-gray-100 px-1 rounded">should</code>, <code class="bg-gray-100 px-1 rounded">must_not</code> 等条件</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="bg-gray-50 p-6 rounded-xl">
                        <h4 class="text-xl font-semibold text-gray-800 mb-4">示例查询</h4>
                        <pre class="bg-gray-800 text-gray-100 p-4 rounded-lg overflow-x-auto">
{
  "query": {
    "bool": {
      "must": [
        { "match": { "title": "Elasticsearch" }},
        { "range": { "date": { "gte": "2023-01-01" }}}
      ],
      "filter": [
        { "term": { "status": "published" }}
      ]
    }
  }
}</pre>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">3.2 聚合操作</h3>
                <p class="text-lg text-gray-700 mb-6 leading-relaxed">
                    Elasticsearch 支持强大的聚合操作，用于对数据进行统计和分析。
                </p>
                
                <div class="grid md:grid-cols-3 gap-6 mb-10">
                    <div class="bg-white p-6 rounded-xl shadow-sm card-hover">
                        <div class="flex items-center mb-3">
                            <div class="bg-blue-100 text-blue-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                                <i class="fas fa-calculator"></i>
                            </div>
                            <h4 class="text-lg font-semibold text-gray-800">指标聚合</h4>
                        </div>
                        <p class="text-gray-600">如 <code class="bg-gray-100 px-1 rounded">avg</code>, <code class="bg-gray-100 px-1 rounded">sum</code>, <code class="bg-gray-100 px-1 rounded">min</code>, <code class="bg-gray-100 px-1 rounded">max</code> 等</p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm card-hover">
                        <div class="flex items-center mb-3">
                            <div class="bg-purple-100 text-purple-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                                <i class="fas fa-chart-pie"></i>
                            </div>
                            <h4 class="text-lg font-semibold text-gray-800">桶聚合</h4>
                        </div>
                        <p class="text-gray-600">如 <code class="bg-gray-100 px-1 rounded">terms</code>, <code class="bg-gray-100 px-1 rounded">date_histogram</code> 等，用于将数据分组</p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm card-hover">
                        <div class="flex items-center mb-3">
                            <div class="bg-green-100 text-green-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                                <i class="fas fa-project-diagram"></i>
                            </div>
                            <h4 class="text-lg font-semibold text-gray-800">管道聚合</h4>
                        </div>
                        <p class="text-gray-600">如 <code class="bg-gray-100 px-1 rounded">avg_bucket</code>, <code class="bg-gray-100 px-1 rounded">derivative</code> 等，用于对聚合结果进行二次计算</p>
                    </div>
                </div>
                
                <div class="bg-gray-50 p-6 rounded-xl">
                    <h4 class="text-xl font-semibold text-gray-800 mb-4">聚合示例</h4>
                    <pre class="bg-gray-800 text-gray-100 p-4 rounded-lg overflow-x-auto">
{
  "aggs": {
    "by_category": {
      "terms": { "field": "category.keyword" },
      "aggs": {
        "avg_price": { "avg": { "field": "price" }},
        "max_price": { "max": { "field": "price" }}
      }
    }
  }
}</pre>
                </div>
            </div>
        </section>

        <!-- Performance Optimization -->
        <section id="optimization" class="mb-24">
            <div class="flex items-center mb-12">
                <div class="bg-indigo-100 text-indigo-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                    <i class="fas fa-tachometer-alt text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">4. Elasticsearch 的性能优化</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">4.1 分片与副本的优化</h3>
                
                <div class="grid md:grid-cols-2 gap-8 mb-10">
                    <div>
                        <h4 class="text-xl font-semibold text-gray-800 mb-4">分片数量</h4>
                        <p class="text-gray-700 mb-4">分片数量应根据数据量和查询负载合理设置，过多的分片会增加集群的管理开销。</p>
                        <div class="bg-indigo-50 p-4 rounded-lg">
                            <p class="text-indigo-700 font-medium">建议：</p>
                            <ul class="list-disc list-inside text-indigo-700">
                                <li>单个分片大小建议在10GB-50GB之间</li>
                                <li>对于日志类数据，可以考虑按月/周创建索引</li>
                                <li>测试环境下可分片数=节点数</li>
                            </ul>
                        </div>
                    </div>
                    
                    <div>
                        <h4 class="text-xl font-semibold text-gray-800 mb-4">副本数量</h4>
                        <p class="text-gray-700 mb-4">副本数量应根据数据的可用性和查询负载需求设置，通常设置为1-2个副本。</p>
                        <div class="bg-purple-50 p-4 rounded-lg">
                            <p class="text-purple-700 font-medium">建议：</p>
                            <ul class="list-disc list-inside text-purple-700">
                                <li>生产环境至少1个副本</li>
                                <li>高查询负载可考虑增加副本数</li>
                                <li>可使用<code class="bg-purple-100 px-1 rounded">index.number_of_replicas</code>动态调整</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">4.2 查询优化</h3>
                
                <div class="grid md:grid-cols-3 gap-6 mb-10">
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <div class="flex items-center mb-3">
                            <div class="bg-blue-100 text-blue-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                                <i class="fas fa-filter"></i>
                            </div>
                            <h4 class="text-lg font-semibold text-gray-800">使用过滤器</h4>
                        </div>
                        <p class="text-gray-600">过滤器不会计算相关性分数，性能优于查询。对于不需要评分的条件，应使用<code class="bg-gray-100 px-1 rounded">filter</code>。</p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <div class="flex items-center mb-3">
                            <div class="bg-purple-100 text-purple-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                                <i class="fas fa-layer-group"></i>
                            </div>
                            <h4 class="text-lg font-semibold text-gray-800">避免深度分页</h4>
                        </div>
                        <p class="text-gray-600">深度分页(如<code class="bg-gray-100 px-1 rounded">from</code>和<code class="bg-gray-100 px-1 rounded">size</code>参数过大)会导致性能下降，建议使用<code class="bg-gray-100 px-1 rounded">search_after</code>或滚动查询(Scroll API)。</p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <div class="flex items-center mb-3">
                            <div class="bg-green-100 text-green-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                                <i class="fas fa-memory"></i>
                            </div>
                            <h4 class="text-lg font-semibold text-gray-800">使用缓存</h4>
                        </div>
                        <p class="text-gray-600">Elasticsearch 提供了查询缓存和请求缓存，合理使用缓存可以显著提升查询性能。</p>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-2xl font-semibold text-gray-800 mb-6">4.3 硬件与配置优化</h3>
                
                <div class="grid md:grid-cols-3 gap-6 mb-10">
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <h4 class="text-lg font-semibold text-gray-800 mb-3">内存配置</h4>
                        <p class="text-gray-600">Elasticsearch 依赖 JVM 内存，建议将 JVM 堆内存设置为物理内存的50%，但不超过32GB。</p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <h4 class="text-lg font-semibold text-gray-800 mb-3">磁盘性能</h4>
                        <p class="text-gray-600">使用 SSD 磁盘可以显著提升索引和查询性能。</p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <h4 class="text-lg font-semibold text-gray-800 mb-3">集群规模</h4>
                        <p class="text-gray-600">根据数据量和查询负载合理规划集群规模，避免单节点负载过重。</p>
                    </div>
                </div>
                
                <div class="highlight-box p-6">
                    <div class="flex items-start">
                        <div class="text-indigo-500 mr-4">
                            <i class="fas fa-cog"></i>
                        </div>
                        <div>
                            <h4 class="font-bold text-gray-800 mb-2">关键配置参数</h4>
                            <ul class="list-disc list-inside text-gray-700 space-y-2">
                                <li><code class="bg-gray-100 px-1 rounded">indices.memory.index_buffer_size</code>：索引缓冲区大小</li>
                                <li><code class="bg-gray-100 px-1 rounded">indices.queries.cache.size</code>：查询缓存大小</li>
                                <li><code class="bg-gray-100 px-1 rounded">thread_pool</code>：各类线程池配置</li>
                                <li><code class="bg-gray-100 px-1 rounded">cluster.routing.allocation</code>：分片分配策略</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Applications -->
        <section id="applications" class="mb-24">
            <div class="flex items-center mb-12">
                <div class="bg-indigo-100 text-indigo-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                    <i class="fas fa-laptop-code text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">5. 实际项目中的应用</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-8 rounded-xl shadow-sm card-hover">
                    <div class="flex items-center mb-5">
                        <div class="bg-blue-100 text-blue-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                            <i class="fas fa-file-alt text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-semibold text-gray-800">5.1 在 ts-log 项目中使用 Elasticsearch</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        在 ts-log 项目中，团队使用 Elasticsearch 存储和分析日志数据。通过合理的分片和副本配置，团队实现了日志的高效存储和查询。
                    </p>
                    <p class="text-gray-700">
                        使用聚合操作，团队能够实时分析日志数据，快速定位问题。
                    </p>
                    <div class="mt-6">
                        <span class="inline-block bg-blue-100 text-blue-600 px-3 py-1 rounded-full text-sm font-medium mr-2">日志分析</span>
                        <span class="inline-block bg-purple-100 text-purple-600 px-3 py-1 rounded-full text-sm font-medium">实时监控</span>
                    </div>
                </div>
                
                <div class="bg-white p-8 rounded-xl shadow-sm card-hover">
                    <div class="flex items-center mb-5">
                        <div class="bg-purple-100 text-purple-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                            <i class="fas fa-search text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-semibold text-gray-800">5.2 在 ts-search 项目中优化查询性能</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        在 ts-search 项目中，团队优化了 Elasticsearch 的查询性能。通过使用过滤器、避免深度分页和合理使用缓存，团队显著提升了搜索响应速度。
                    </p>
                    <div class="mt-6">
                        <span class="inline-block bg-green-100 text-green-600 px-3 py-1 rounded-full text-sm font-medium mr-2">查询优化</span>
                        <span class="inline-block bg-yellow-100 text-yellow-600 px-3 py-1 rounded-full text-sm font-medium">性能调优</span>
                    </div>
                </div>
                
                <div class="bg-white p-8 rounded-xl shadow-sm card-hover">
                    <div class="flex items-center mb-5">
                        <div class="bg-green-100 text-green-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                            <i class="fas fa-chart-line text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-semibold text-gray-800">5.3 在 ts-analytics 项目中使用聚合操作</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        在 ts-analytics 项目中，团队使用 Elasticsearch 的聚合操作对用户行为数据进行分析。通过桶聚合和管道聚合，团队能够生成复杂的统计报表，支持业务决策。
                    </p>
                    <div class="mt-6">
                        <span class="inline-block bg-red-100 text-red-600 px-3 py-1 rounded-full text-sm font-medium mr-2">行为分析</span>
                        <span class="inline-block bg-indigo-100 text-indigo-600 px-3 py-1 rounded-full text-sm font-medium">数据可视化</span>
                    </div>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section id="best-practices" class="mb-24">
            <div class="flex items-center mb-12">
                <div class="bg-indigo-100 text-indigo-600 w-12 h-12 rounded-lg flex items-center justify-center mr-4">
                    <i class="fas fa-star text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">6. 最佳实践</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 text-blue-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                            <i class="fas fa-boxes"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">6.1 合理规划索引</h3>
                    </div>
                    <p class="text-gray-600">
                        根据业务需求和数据特点，合理规划索引结构，避免单个索引过大或过小。可以考虑按时间、业务线或数据类型划分索引。
                    </p>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 text-purple-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                            <i class="fas fa-heartbeat"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">6.2 定期维护集群</h3>
                    </div>
                    <p class="text-gray-600">
                        定期监控集群状态，及时处理节点故障和分片不平衡问题。使用 <code class="bg-gray-100 px-1 rounded">_cat</code> API 和 Kibana 监控工具，实时了解集群健康状况。
                    </p>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="bg-green-100 text-green-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3">
                            <i class="fas fa-cloud-upload-alt"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">6.3 数据备份与恢复</h3>
                    </div>
                    <p class="text-gray-600">
                        定期备份 Elasticsearch 数据，防止数据丢失。使用快照(Snapshot)功能，将数据备份到远程存储(如 S3、HDFS)。
                    </p>
                </div>
            </div>
            
            <div class="mt-12 bg-indigo-50 rounded-xl p-8">
                <div class="flex items-start">
                    <div class="text-indigo-500 mr-4 text-2xl">
                        <i class="fas fa-lightbulb"></i>
                    </div>
                    <div>
                        <h3 class="text-2xl font-bold text-gray-800 mb-4">Elasticsearch 优化检查清单</h3>
                        <ul class="list-disc list-inside text-gray-700 space-y-3">
                            <li>合理设置分片数量和大小(10GB-50GB/分片)</li>
                            <li>为生产环境配置至少1个副本</li>
                            <li>使用SSD存储提高I/O性能</li>
                            <li>为JVM分配不超过50%物理内存(最大32GB)</li>
                            <li>使用过滤器(Filter)替代不必要的查询(Query)</li>
                            <li>避免深度分页，使用search_after或Scroll API</li>
                            <li>定期监控集群健康状态和性能指标</li>
                            <li>建立定期备份机制</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="max-w-4xl mx-auto px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">专注于前沿技术分享与实践</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition-colors duration-300">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            securityLevel: 'loose'
        });
        
        // Update active nav link on scroll
        const sections = document.querySelectorAll('section');
        const navLinks = document.querySelectorAll('.nav-link');
        
        window.addEventListener('scroll', () => {
            let current = '';
            
            sections.forEach(section => {
                const sectionTop = section.offsetTop;
                const sectionHeight = section.clientHeight;
                
                if (pageYOffset >= (sectionTop - 100)) {
                    current = section.getAttribute('id');
                }
            });
            
            navLinks.forEach(link => {
                link.classList.remove('active-nav');
                link.classList.remove('text-gray-700');
                link.classList.add('text-gray-500');
                
                if (link.getAttribute('href') === `#${current}`) {
                    link.classList.add('active-nav');
                    link.classList.remove('text-gray-500');
                    link.classList.add('text-gray-700');
                }
            });
        });
    </script>
</body>
</html>